Re: ORDER BY CASE ... - Mailing list pgsql-sql

From Mathieu Arnold
Subject Re: ORDER BY CASE ...
Date
Msg-id B6687EF0F11B9302F7A56031@[192.168.9.47]
Whole thread Raw
In response to Re: ORDER BY CASE ...  (Mario Splivalo <mario.splivalo@mobart.hr>)
Responses Re: ORDER BY CASE ...  (Mario Splivalo <mario.splivalo@mobart.hr>)
List pgsql-sql
+-le 13/02/2006 16:47 +0100, Mario Splivalo a dit :
| On Mon, 2006-02-13 at 16:39 +0100, Mathieu Arnold wrote:
|> | 
|> | I tought I'd get differently sorted data, since in the first query I
|> | said 5=5, and in second I said 5=6. 
|> 
|> Well, no, in the first, the result of the CASE is 2, and in the second 3,
|> it means that for every line, it'll sort using "2" as value for the first,
|> and "3" for the second query.
|> 
| 
| Yes, I realized just a second ago that when ORDER BY is CASED, numbers
| aren't the column numbers, but the integers itself.
| 
| It works like this:
| 
| ORDER BY (CASE WHEN 5=5 THEN "from"::varchar ELSE
| receiving_time::varchar) DESC.
| 
| Is there a way to have DESC/ASC inside of a CASE?
| 
|     Mario

No, you don't understand, you should do something like :

case when foo = bar then from else receiving_time desc end

-- 
Mathieu Arnold


pgsql-sql by date:

Previous
From: Reinoud van Leeuwen
Date:
Subject: Re: ORDER BY CASE ...
Next
From: Bryce Nesbitt
Date:
Subject: Re: Very slow updates when using IN syntax subselect